package com.sky.financelake.utils;

import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatTextView;

import com.facebook.shimmer.ShimmerFrameLayout;
import com.sky.financelake.R;
import com.sky.financelake.databinding.LoadingLayoutBinding;

import dagger.Component;
import dagger.Module;
import dagger.hilt.EntryPoint;
import dagger.hilt.InstallIn;
import dagger.hilt.android.AndroidEntryPoint;
import dagger.hilt.components.SingletonComponent;

/**
 * @author : 陈欣健
 * @describe :
 * @since :2016-09-10 下午6:37
 **/
public class LoadingUtil {
    private Activity activity;
    private View view;
    private LoadingLayoutBinding binding;
    private ShimmerFrameLayout shimmer;
    private AppCompatTextView tvShimmer;

    public static LoadingUtil newInstance(LoadingLayoutBinding binding) {
        return new LoadingUtil(binding);
    }

    public static LoadingUtil newInstance(View view) {
        return new LoadingUtil(view);
    }

    public static LoadingUtil newInstance(Activity activity) {
        return new LoadingUtil(activity);
    }

    private LoadingUtil(Activity activity) {
        this.activity = activity;
        initLoading(activity);
    }

    private LoadingUtil(LoadingLayoutBinding binding) {
        this.binding = binding;
        initLoading(binding);
    }

    private LoadingUtil(View view) {
        this.view = view;
        initLoading(view);
    }



    protected void initLoading(View view) {
        shimmer = (ShimmerFrameLayout)view.findViewById(R.id.shimmer_container);
        tvShimmer = (AppCompatTextView) view.findViewById(R.id.tv_shimmer);
        startShimmer();
    }
    protected void initLoading(LoadingLayoutBinding binding) {
        shimmer = view.findViewById(R.id.shimmer_container);
        tvShimmer = (AppCompatTextView) view.findViewById(R.id.tv_shimmer);
        startShimmer();
    }

    protected void initLoading(Activity activity) {
        LoadingLayoutBinding binding = LoadingLayoutBinding.inflate(activity.getLayoutInflater());
        shimmer = binding.shimmerContainer;
        tvShimmer = binding.tvShimmer;
        startShimmer();
    }

    private void startShimmer() {
        if (shimmer != null && tvShimmer != null) {
            shimmer.startShimmer();
        }
    }


    public void hide() {
        shimmer.stopShimmer();
        Log.i("LoadingUtil", "hide: ");
        shimmer.setVisibility(View.GONE);
    }

}
